/**
 * @description TODO
 * @author lizhishu
 * @date 20123/03/17 21:52
 *
 */

let net = require('net')
/**
 *
 * @param {*} host
 * @param {*} port
 */
async function checkIp(host, port) {
  return await new Promise((resolve) => {
    let client = net.createConnection({ host, port })
    client.setTimeout(10000)
    client.on('timeout', () => {
      // console.warn('timeout')
      client.destroy()
      resolve(false)
    })
    client.on('close', () => {
      // console.warn('close')
      client.destroy()
      resolve(false)
    })
    client.on('connect', () => {
      client.destroy()
      resolve(host + ':' + port)
    })
    client.on('error', () => {
      // console.warn('error')
      resolve(false)
    })
  })
}
export { checkIp }
